#include "common.hpp"
#include "log.hpp"

int main()
{
    //Log log;
    Log log(ONE_FILE);

    
    //打开管道
    int fd = open(Filename, O_WRONLY);
    if(fd < 0)
    {
        //perror("open");
        log(Fatal, "error mess: %s, error code: %d", strerror(errno), errno);
        exit(OPEN_ERR);
    }

    log(Info, "open pipe success");

    //进行通信——写端
    while(true)
    {
        std::string send;
        std::cout << "client send: ";
        std::getline(std::cin, send);
        write(fd, send.c_str(), send.size());
    }


    //关闭管道
    int ret = close(fd);
    if(ret == -1)
    {
        //perror("close");
        log(Error, "error mess: %s, error code: %d", strerror(errno), errno);
        exit(CLOSE_ERR);
    }

    log(Info, "close pipe success");

    return 0;
}